﻿using SqlPerfomance.V2.DomainModel.Enums;
using SqlPerfomance.V2.DomainModel.Models;
using SqlPerfomance.V2.DomainModel.NodeTree.Interfaces;
using System;
using System.Collections.Generic;
using System.Data.Common;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SqlPerfomance.V2.DAL
{
    public abstract class RealDataRepository<T> : AbstractRepository<T>
    {
        public abstract ITree<T> CreateTree(INode<CommonTreeNode> commonTree);

        public void ClearCache(ConnectionStrings connectionString)
        {
            string sql = string.Empty;
            if(connectionString == ConnectionStrings.SqlServerConnectionString)
            {
                sql = "CHECKPOINT DBCC DROPCLEANBUFFERS";
            }
            else
            {
                sql = "RESET QUERY CACHE;FLUSH QUERY CACHE;";
            }
            ExecuteQuery(sql, connectionString);
        }
    }
}
